Skip to content

fix(bgz-tensor): resolve 5 CI-invisible test failures (3 stale tests + 1 slice-bounds bug)#506

Merged
AdaWorldAPI merged 1 commit into
mainfrom
claude/sleepy-cori-aRK2x
Jun 16, 2026
Merged

fix(bgz-tensor): resolve 5 CI-invisible test failures (3 stale tests + 1 slice-bounds bug)#506
AdaWorldAPI merged 1 commit into
mainfrom
claude/sleepy-cori-aRK2x

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

Why

bgz-tensor is excluded from CI — no workflow tests its manifest (build.yml/rust-test.yml/style.yml only cover lance-graph, lance-graph-contract, deepnsm, jc). As a result cargo test -p bgz-tensor was 195 passed / 5 failed on main, and had been for an unknown number of PRs. Surfaced by a local sweep of the CI-uncovered standalone crates (the same gap that hid the causal-edge red fixed in #498).

Each red was diagnosed as test-stale vs code-bug before fixing — no assertions were blanket-bumped to green (which would have papered over the real defect).

The 5 failures

Test-stale (the code was correct; the test's expected value had drifted):

Test Was Root cause
gamma_calibration::calibration_profile_size asserted 40 byte_size() is genuinely 48 = RoleGamma 36 B ([f32;8]=32 + phi_scale=4) + CosineGamma 12 B. The stale // 28 + 12 comment assumed 7 roles; the struct has 8.
hhtl_cache::test_hhtl_cache_256_size size formula short by 16 B serialize() writes a 16-byte gamma_meta trailer ([lo_gamma, hi_gamma, phi_scale, role_id]) that the test's byte formula omitted. Added + 16.
hhtl_d::hhtl_d_entry_roundtrip used 0x3C00 "BF16 1.0" 0x3C00 is the IEEE-half (F16) bit pattern for 1.0 (decodes to 0.0078125 under BF16). Real BF16 1.0 is 0x3F80. bf16_to_f32 (top-16-bits-of-f32) was correct; the literal was wrong.

Code bug (a genuine robustness defect, not a stale test):

  • matryoshka::{encode_decode_roundtrip_nonzero, roundtrip_quality_reasonable} panicked with an out-of-bounds slice when the SVD basis rank is lower than the band profile's nominal max — e.g. building SvdBasis::build(rows, 128) from only 50 sample rows yields a rank-50 basis, but BandProfile::standard(128, …) has bands starting at 64/192. encode_row sliced coeffs[band.start..] with an unguarded start; decode_row wrote coeffs[band.start + i] past the buffer.

    • Fix (symmetric, both sides): encode clamps the slice start (it was only clamping end); decode caps the per-band component count to the coeff buffer (n.min(coeffs.len().saturating_sub(band.start))). A band entirely beyond the available rank now degrades to empty on both sides, so the byte stream stays in sync — the roundtrip + quality assertions (cosine > 0.8, len == 256) pass.

    This one was a latent crash, not merely a stale test: any production use with a rank-deficient basis (fewer sample rows than requested components) would panic.

Verification (local — this sandbox has protoc + full toolchain)

cargo test  -p bgz-tensor                        → 200 passed / 0 failed   (was 195/5)
cargo fmt   -p bgz-tensor -- --check             → clean
cargo clippy -p bgz-tensor --all-targets -- -D warnings → clean

Diff is 9 insertions / 6 deletions across 4 files — the three one-line test corrections (each with a corrected explanatory comment) plus the two-site matryoshka guard.

Follow-up (not in this PR)

The root cause is structural: CI tests only 4 of ~30 crates. Two CI-invisible reds have now been found and fixed this session (causal-edge #498, bgz-tensor here). A separate PR should add the disk-cheap standalone crates (bgz-tensor, bgz17, causal-edge, helix, highheelbgz) to rust-test.yml so this class of regression is caught at PR time. Flagging for the workflow owner rather than bundling a CI change into a test-fix PR.


Generated by Claude Code

…+ 1 slice-bounds bug)

bgz-tensor is excluded from CI (no workflow tests its manifest), so these
reds accumulated unseen on main — surfaced by a local sweep of the
CI-uncovered standalone crates. Diagnosed each as test-stale vs code-bug
before fixing; did not blanket-bump assertions.

Test-stale (code was correct, expected values drifted):
- gamma_calibration: byte_size() is 48 (RoleGamma 36 + CosineGamma 12),
  not 40 — the struct has 8 roles (32B)+phi_scale(4B)=36B; the stale
  '28+12' comment assumed 7 roles.
- hhtl_cache: serialize() writes a 16-byte gamma_meta trailer that the
  test's size formula omitted; added + 16.
- hhtl_d: 0x3C00 is the IEEE-half (F16) bit pattern for 1.0; real BF16
  1.0 is 0x3F80. bf16_to_f32 was correct; the test literal was wrong.

Code-bug (genuine robustness fix, both encode + decode):
- matryoshka encode_row/decode_row panicked when the SVD basis rank is
  lower than the band profile's nominal max (fewer sample rows than
  requested components → a band extends past the available coeffs).
  encode: clamp slice start (was only clamping end); decode: cap the
  per-band component count to the coeff buffer. Symmetric, so the byte
  stream stays in sync; roundtrip + quality assertions pass.

Verified: bgz-tensor 200 passed / 0 failed (was 195/5); fmt clean;
clippy -p bgz-tensor --all-targets -D warnings clean.
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@AdaWorldAPI, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 15 minutes and 2 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ec8cfb43-eb78-4396-9153-5022856bc28d

📥 Commits

Reviewing files that changed from the base of the PR and between cb14704 and 7472ce4.

📒 Files selected for processing (4)
  • crates/bgz-tensor/src/gamma_calibration.rs
  • crates/bgz-tensor/src/hhtl_cache.rs
  • crates/bgz-tensor/src/hhtl_d.rs
  • crates/bgz-tensor/src/matryoshka.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants